
/**
 * 获取节气
 *
 * @param {*} DateGL Date 对象方法
 * @return {*}
 */
function getSolarTerm(DateGL) {
  const SolarTermStr = ["小寒", "大寒", "立春", "雨水", "惊蛰", "春分",
    "清明", "谷雨", "立夏", "小满", "芒种", "夏至",
    "小暑", "大暑", "立秋", "处暑", "白露", "秋分",
    "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"];
  const DifferenceInMonth = [1272060, 1275495, 1281180, 1289445, 1299225, 1310355,
    1321560, 1333035, 1342770, 1350855, 1356420, 1359045,
    1358580, 1355055, 1348695, 1340040, 1329630, 1318455,
    1306935, 1297380, 1286865, 1277730, 1274550, 1271556];
  const DifferenceInYear = 31556926;
  const BeginTime = new Date(1901 / 1 / 1);
  BeginTime.setTime(947120460000);
  for (; DateGL.getFullYear() < BeginTime.getFullYear();) {
      BeginTime.setTime(BeginTime.getTime() - DifferenceInYear * 1000);
  }
  for (; DateGL.getFullYear() > BeginTime.getFullYear();) {
      BeginTime.setTime(BeginTime.getTime() + DifferenceInYear * 1000);
  }
  for (var M = 0; DateGL.getMonth() > BeginTime.getMonth(); M++) {
      BeginTime.setTime(BeginTime.getTime() + DifferenceInMonth[M] * 1000);
  }
  if (DateGL.getDate() > BeginTime.getDate()) {
      BeginTime.setTime(BeginTime.getTime() + DifferenceInMonth[M] * 1000);
      M++;
  }
  if (DateGL.getDate() > BeginTime.getDate()) {
      BeginTime.setTime(BeginTime.getTime() + DifferenceInMonth[M] * 1000);
      M === 23 ? M = 0 : M++;
  }
  var JQ = "二十四节气";
  let solarTerm = {
      date: '二十四节气',
      solarTermStr: '小满'
  }
  if (DateGL.getDate() === BeginTime.getDate()) {
      JQ += "   今日 <font color='#598F03'><b>" + SolarTermStr[M] + "</b></font>";
      solarTerm = {
       date: '今日',
       solarTermStr: SolarTermStr[M]
      }
  } else if (DateGL.getDate() === BeginTime.getDate() - 1) {
      JQ += "　 明日 <font color='#598F03'><b>" + SolarTermStr[M] + "</b></font>";
      solarTerm = {
          date: '明日',
          solarTermStr: SolarTermStr[M]
         }
  } else if (DateGL.getDate() === BeginTime.getDate() - 2) {
      JQ += "　 后日 <font color='#598F03'><b>" + SolarTermStr[M] + "</b></font>";
      solarTerm = {
          date: '后日',
          solarTermStr: SolarTermStr[M]
         }
  } else {
      JQ = " 二十四节气";
      if (DateGL.getMonth() === BeginTime.getMonth()) {
          JQ += " 本月";
      } else {
          JQ += " 下月";
      }
      
      solarTerm = {
          date: JQ + BeginTime.getDate() + "日",
          solarTermStr: SolarTermStr[M]
         }
      JQ += BeginTime.getDate() + "日" + "<font color='#598F03'><b>" + SolarTermStr[M] + "</b></font>";
  }
  return {JQ,solarTerm};
}


/**
 * 获取第n天的时间
 * @param {number} [n=0]
 * @return {*}
 */
function beforeDay(n = 0) {
    // 秒的时间戳
    const day =  Date.parse(new Date()) / 1000 - n * 86400
    return new Date(parseInt(day) * 1000)
}


module.exports = {
  getSolarTerm,beforeDay
}

